package cn.itsource.hrm.utils;

import cn.itsource.hrm.domain.User;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

//工具类
public class MyTools {

    //获取用户测试数据
    public static List<User> getTestUserList(int count, boolean createPrimaryKey){
        List<User> userList = new ArrayList<>();
        User u = null;
        Date now = new Date();
        for(int i=1; i<=count; i++){
            u = new User();
            if(createPrimaryKey){
                u.setId(Integer.valueOf(getRandomLength(8)));
            }
            u.setAddress("湖北省武汉市江夏区香港路123号宇宙花园小区"+ i + "栋" + i + "楼" + i + "号");
            u.setAge(i);
            u.setPhone(MyTools.getRandomLength(11));
            if(i % 2 ==0){
                u.setSex("男");
                u.setNationality("大中国");
                u.setNation("汉族");
                u.setMajor("宇宙最强Java专业" + i);
                u.setSchool("武汉大学" + i + "号");
                u.setUdesc("我是一个Java大神，" + i + "我最牛B");
                u.setUsername("小民同学" + i + "号");
            }else{
                u.setSex("女");
                u.setNationality("中国大");
                u.setNation("苗族");
                u.setMajor("宇宙最强PHP专业" + i);
                u.setSchool("清华大学" + i + "号");
                u.setUdesc("我是一个PHP架构师，" + i + "你们服不服.....");
                u.setUsername("语文同学" + i + "号");
            }
            u.setDeptid(i);
            u.setCreatetime(now);
            u.setIdcard(MyTools.getRandomLength(18));
            u.setQq(MyTools.getRandomLength(11));
            userList.add(u);
        }
        return userList;
    }

    //根据文件全路径删除文件
    public static void deleteFile(String filePath){
        File file = new File(filePath);
        if(file.exists()){
            file.delete();
        }
    }

    public static void main(String[] args) {
        System.out.println(getFolderFile("E:\\excel"));
    }

    //读取某个目录下所有文件全路径
    public static List<String> getFolderFile(String path){
        List<String> files = new ArrayList<>();
        File file = new File(path);
        File[] tempList = file.listFiles();
        for (int i = 0; i < tempList.length; i++) {
            if (tempList[i].isFile()) {
                //如果是文件
                files.add(tempList[i].toString());
            }
            if (tempList[i].isDirectory()) {
                //如果是文件夹
            }
        }
        return files;
    }

    //获取指定区间的随机整数
    public static int getRandom(int min, int max) {
        return min + (int) (Math.random() * (max - min));
    }

    //生成指定位数的随机数
    public synchronized static String getRandomLength(int length) {
        String val = "";
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            val += String.valueOf(random.nextInt(10));
        }
        return val;
    }

}
